﻿// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Collections;
using Emotive.Otf.OtxEditor.Core;

namespace Emotive.Otf.OtxEditor.Debugging
{
	/// <summary>
	/// Creates debuggers.
	/// </summary>
	/// <attribute name="class" use="required">
	/// Name of the IDebugger class.
	/// </attribute>
	/// <attribute name="supportsStart" use="optional">
	/// Specifies if the debugger supports the 'Start' command. Default: true
	/// </attribute>
	/// <attribute name="supportsStartWithoutDebugger" use="optional">
	/// Specifies if the debugger supports the 'StartWithoutDebugger' command. Default: true
	/// </attribute>
	/// <attribute name="supportsStop" use="optional">
	/// Specifies if the debugger supports the 'Stop' (kill running process) command. Default: true
	/// </attribute>
	/// <attribute name="supportsStepping" use="optional">
	/// Specifies if the debugger supports stepping. Default: false
	/// </attribute>
	/// <attribute name="supportsExecutionControl" use="optional">
	/// Specifies if the debugger supports execution control (break, resume). Default: false
	/// </attribute>
	/// <usage>Only in /SharpDevelop/Services/DebuggerService/Debugger</usage>
	/// <returns>
	/// An DebuggerDescriptor object that exposes the attributes and the IDebugger object (lazy-loading).
	/// </returns>
	public class DebuggerDoozer : IDoozer
	{
		/// <summary>
		/// Gets if the doozer handles codon conditions on its own.
		/// If this property return false, the item is excluded when the condition is not met.
		/// </summary>
		public bool HandleConditions {
			get {
				return false;
			}
		}
		
		public object BuildItem(object args)
		{
			return new DebuggerDescriptor(null);
		}
	}
	
	public class DebuggerDescriptor
	{
		object codon;
		
		public DebuggerDescriptor(object codon)
		{
			this.codon = codon;
		}
		
		IDebugger debugger;
		
		public IDebugger Debugger {
			get {
                //if (debugger == null)
                    //debugger = (IDebugger)codon.AddIn.CreateObject(codon.Properties["class"]);
				return debugger;
			}
		}
		
		public bool SupportsStart {
			get {
				return false;
			}
		}
		
		public bool SupportsStartWithoutDebugging {
			get {
				return false;
			}
		}
		
		public bool SupportsStop {
			get {
				return false;
			}
		}
		
		public bool SupportsStepping {
			get {
				return true;
			}
		}
		
		public bool SupportsExecutionControl {
			get {
				return true;
			}
		}
		
		public bool SupportsAttaching {
			get {
				return true;
			}
		}

		public bool SupportsDetaching {
			get {
				return true;
			}
		}		
	}
}
